def list_exts files
  exts = Array.new
  files.each { |f| exts.push(File.extname(f)) }
  exts.uniq
end

def files_same_exts (files)
  exts = list_exts(files)
  res = Array.new
  exts.each { |e| res.push(files.select {|f| File.extname(f) == e}) }
#  res.reject! { |i| i.size == 1 }
  res
end

def list_lengths files
  lengths = Array.new
  files.each { |f| lengths.push(f.length) }
  lengths.uniq
end

def files_same_length (files)
  lengths = list_lengths(files)
  res = Array.new
  lengths.each do |l|
    res.push(files.select {|f| f.length == l})
  end 
#  res.reject! { |i| i.size == 1 }
  res
end

def sort_files (files)
  p files
  files.sort!
  p files
  res = Array.new
  files_same_exts(files).each { |f| files_same_length(f).each {|a| res.push(a)}}
  res.flatten
end  
